﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Work06._03
{
    class Exam
    {
        static int count = 0;
        static float num;
        static float sum = 0;
        static float avg;
        static List<float> list = new List<float>();
        static void Main(string[] args)
        {
            try
            {
                receive();

            }
            catch (FormatException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("异常已处理");

            }
            catch (OverflowException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("异常已处理");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("异常已处理");
            }
            finally
            {
                Console.WriteLine("");
            }


        }

        private static void receive()
        {
            for (int i = 0; i < 1; i++)
            {
                Console.WriteLine("请录入考生成绩：");
                num = float.Parse(Console.ReadLine());
                list.Add(num);
                sum = sum + num;
                Console.WriteLine("是否需要继续（y/n）");
                string YN = Console.ReadLine();
                if (YN.Equals("n"))
                {
                    avg = sum / list.Count;
                    Console.WriteLine("总学生数:{0}，总分数:{1}，平均分:{2}", list.Count, sum, avg);

                }
                else if (YN.Equals("y"))
                {
                    receive();
                }
                else
                {
                    Console.WriteLine("输入正确的指令！（是 or 否）");
                }
            }
        }
    }

}
